#include "stm32f10x.h"
#include "key.h"

uint8_t key_num;

uint8_t Key_GetNum(void)
{
    uint8_t temp;
    if(key_num)
    {
        temp = key_num;
        key_num = 0;
        return temp;
    }
    return 0;
}

uint8_t Key_GetState(void)
{
    if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15)==0)
    {
        return up;
    }
    if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14) == 0)
    {
        return down;
    }
    if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == 0)
    {
        return enter;
    }
    return null;
}

void Key_Tick(void)
{
    static uint8_t count;
    static uint8_t CurrState, PrevState;
    count++;
    if(count>=20)
    {
        count = 0;
        PrevState = CurrState;
        CurrState = Key_GetState();
        if(CurrState==0 && PrevState!=0)
        {
            key_num = PrevState;
        }
    }

}
